package com.itheima.controller;

import com.itheima.pojo.domain.Emp;
import com.itheima.pojo.vo.PageResult;
import com.itheima.pojo.Result;
import com.itheima.pojo.dto.EmpQueryParamDTO;
import com.itheima.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 员工管理
 */
@Slf4j
@RequestMapping("/emps")
@RestController()
public class EmpController {

    @Autowired
    private EmpService empService;

    /**
     * 分页查询所有员工信息
     * @param empQueryParamDto
     * @return
     */
    @GetMapping
    public Result list(EmpQueryParamDTO empQueryParamDto) {
        log.info("分页查询所有员工信息");
        PageResult<Emp> pageResult = empService.list(empQueryParamDto);
        return Result.success(pageResult);
    }

    /**
     * 查询所有员工信息
     * @return
     */
    @GetMapping("/list")
    public Result listAll() {
        log.info("查询所有员工信息");
        List<Emp> list = empService.listAll();
        return Result.success(list);
    }
    /**
     * 根据id查询
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result getEmpInfo(@PathVariable Integer id){
        log.info("根据id查询");
        Emp emps = empService.getEmpInfoById(id);
        return Result.success(emps);
    }

    /**
     * 新增员工
     * @param emp
     * @return
     */
    @PostMapping
    public Result addEmp(@RequestBody Emp emp){
        log.info("添加员工信息");
        empService.addEmpInfo(emp);
        return Result.success();
    }

    /**
     * 修改员工信息
     * @param emp
     * @return
     */
    @PutMapping
    public Result updateEmp(@RequestBody Emp emp){
        log.info("员工修改");
        empService.updateEmpInfo(emp);
        return Result.success();
    }
    /**
     * 删除员工信息
     * @param ids
     * @author ：ayao
     */
    @DeleteMapping()
    public Result deleteEmp(@RequestParam List<Integer> ids){
        log.info("员工删除");
        empService.deleteEmpInfo(ids);
        return Result.success();
    }



}